#ifndef DOUBLE_LINKLIST_H
#define DOUBLE_LINKLIST_H

#include "List.h"

class DoubleLinkList : public List {

public:
    virtual Status InitList(void) override;
    virtual Status DestoryList(void)override;
    virtual Status ClearList(void)override;
    virtual Status ListEmpty(void)override;
    virtual int ListLength(void)override;
    virtual Status GetElem(int i, ElemType *e)override;
    virtual int LocateElem(ElemType e, Status(*compare)(ElemType, ElemType))override;
    virtual Status PriorElem(ElemType cur, ElemType *prev)override;
    virtual Status NextElem(ElemType cur, ElemType *next)override;
    virtual Status ListInsert(int i, ElemType e)override;
    virtual Status ListDelete(int i, ElemType *e)override;
    virtual Status ListTraverse(void) override;
    virtual Status ListHeadInsert(ElemType e);
    virtual Status ListTailInsert(ElemType e);

private:
    struct DoubleLinkNode {
        ElemType e;
        DoubleLinkNode *prev;
        DoubleLinkNode *next;
    };

    DoubleLinkNode *L;
    DoubleLinkNode *GetElemP(int i)
    {
        DoubleLinkNode *p = L;

        if (i < 0 || i > ListLength())
            return FALSE;

        for (int j = 0; j < i; j++)
            p = p->next;

        return p;

    }
};

#endif